import cv2
import numpy as np
# 读取视频
cap = cv2.VideoCapture('Y:/MP4/1.mp4')
fps = int(cap.get(cv2.CAP_PROP_FPS))
frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
print(f'frame_width:{frame_width},frame_height:{frame_height},fps:{fps}')

# 输出视频编码器设置
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('Y:/MP4/output.avi', fourcc, fps, (frame_width, frame_height))

while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
        break
    # 假设我们知道水印的位置和大小
    y1, y2, x1, x2 = 411, 481, 652, 907  # 修正后的坐标
    watermark_area = frame[y1:y2, x1:x2]  #提取水印区域
    blurred_area = cv2.GaussianBlur(watermark_area, (5, 5), 0)  # 应用高斯模糊
    frame[y1:y2, x1:x2] = blurred_area  # 将模糊后的区域放回原位
    out.write(frame)

cap.release()
out.release()